package com.uft.security.tam.utils;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.uft.controller.DatapowerController;

public class MockAuthFilter implements Filter {
	

	
	private  static Logger  logger = Logger.getLogger(MockAuthFilter.class);

	public void destroy() {
		// TODO Auto-generated method stub
		
		
	}

	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
			FilterChain filterChain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		logger.debug("Entered doFilter() method ");
		if(servletRequest instanceof HttpServletRequest){
			HttpServletRequest httpServletRequest = (HttpServletRequest)servletRequest;
			FakeHeadersRequest request = new FakeHeadersRequest(httpServletRequest);
		//	RequestContextHolder.setRequestAttributes(attributes);
			RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
			filterChain.doFilter(request, servletResponse);
		}else{
			filterChain.doFilter(servletRequest, servletResponse);
		}
		logger.debug("Exited doFilter() method");
		
		
		
		
	}

	public void init(FilterConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

}
